// 字节面试题
function strForamt(str) {
    let res = []
    let temp = []
    let s = ""
    for (let i = 0; i < str.length; i++) {
        if (str.charAt(i) === " ") {
            if (s !== "") {
                temp.push(s)
                s = ""
            }
        } else if (str.charAt(i) === "\n") {
            if (s !== "") {
                temp.push(s)
                s = ""
            }
            if(temp.length > 0) {

                res.push(temp)
                temp = []
            }
        } else {
            s += str.charAt(i)
        }
    }
    if (s !== "") {
        res[res.length - 1].push(s)
    }
    return res
}
let str = `
1 2 4342   3 4 5
23 4 
    4 599  
        
`
console.log(strForamt(str));